// 引入封装好的网络请求包
import {
  post,
  get,
  post_upload
} from 'request.js';

// 本地服务器地址
//const serverHostUrl = "https://c5b391103588.ngrok.io/mars";
const serverHostUrl = "http://localhost:8085/mars";


/**
 * 用户登录
 */
const loginUrl = serverHostUrl + '/user/login/weixin';

/**
 * 广告列表
 */
const bannerListUrl = serverHostUrl + '/banner/list';

/**
 * 添加笔记
 */
const addNotesUrl = serverHostUrl + '/food/notes/createNotes';

/**
 * 用户反馈
 */
const addFeedbackUrl = serverHostUrl + '/food/feedback/create';

/**
 * 笔记列表
 */
const listNotesUrl = serverHostUrl + '/food/notes/list';

/**
 * 删除笔记
 */
const deleteNotesUrl = serverHostUrl + '/food/notes/delete';
/**
 * 菜系列表
 */
const foodTypeListUrl = serverHostUrl + '/foodType/list';
/**
 * 菜系详情
 */
const foodTypeDetailUrl = serverHostUrl + '/foodType/detail';
/**
 * 美食推荐
 */
const foodRecommendListUrl = serverHostUrl + '/food/recommend';
/**
 * 美食详情
 */
const foodDetailUrl = serverHostUrl + '/food/detail';
/**
 * 点赞美食 
 */
const foodLikeUrl = serverHostUrl + '/food/like';

/**
 * 点赞列表
 */
const foodLikesUrl = serverHostUrl + '/food/foodLikes';
/**
 * 收藏列表
 */
const foodCollectListUrl = serverHostUrl + '/food/collectList';

/**
 * 收藏美食
 */
const foodCollectUrl = serverHostUrl + '/food/collect';

/**
 * 创建评论
 */
const foodCommentUrl = serverHostUrl + '/food/comment/createComment';


/**
 * 评论列表
 */
const foodCommentListUrl = serverHostUrl + '/food/comment/list';

/**
 * 图片上传
 */
const uploadFileUrl = serverHostUrl + '/upload/img';

/**
 * 发布美食
 */
const publishFoodUrl = serverHostUrl + '/food/publish';



/**
 * 食谱列表
 */
const mineFoodsUrl = serverHostUrl + '/food/mineFoods';

/**
 * 分类详情列表
 */
const categoryDetailUrl = serverHostUrl + '/food/categoryDetail';


/**
 * 分类详情列表
 * @param {*} params 
 * @param {*} success 
 * @param {*} fail 
 */
const categoryDetailFunc = (params, success, fail) => {
  get(categoryDetailUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}


/**
 * 我的食谱
 * @param {*} params 
 * @param {*} success 
 * @param {*} fail 
 */
const mineFoodsFunc = (params, success, fail) => {
  get(mineFoodsUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 发布美食
 * @param {*} params 
 * @param {*} success 
 * @param {*} fail 
 */
const publishFoodFunc = (params, success, fail) => {
  post(publishFoodUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}


/**
 * 图片上传
 * @param {t} params 
 * @param {*} success 
 * @param {*} fail 
 */
const uploadFileFunc = (params, success, fail) => {
  post_upload(uploadFileUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 评论列表
 * @param {*} params 
 * @param {*} success 
 * @param {*} fail 
 */
const foodCommentListFunc = (params, success, fail) => {
  get(foodCommentListUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 评论
 * @param {*} params 
 * @param {*} success 
 * @param {*} fail 
 */
const foodCommentFunc = (params, success, fail) => {
  get(foodCommentUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 收藏列表
 * @param {} params 
 * @param {*} success 
 * @param {*} fail 
 */
const foodCollectListFunc = (params, success, fail) => {
  get(foodCollectListUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 收藏美食
 * @param {*} params 
 * @param {*} success 
 * @param {*} fail 
 */
const foodCollectFunc = (params, success, fail) => {
  get(foodCollectUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 点赞列表
 * @param  params 
 * @param {*} success 
 * @param {*} fail 
 */
const foodLikesFunc = (params, success, fail) => {
  get(foodLikesUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 点赞美食
 * @param {*} params 
 * @param {*} success 
 * @param {*} fail 
 */
const foodLikeFunc = (params, success, fail) => {
  get(foodLikeUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 美食详情
 * @param {*} params 
 * @param {*} success 
 * @param {*} fail 
 */
const foodDetailFunc = (params, success, fail) => {
  get(foodDetailUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 美食推荐
 * @param {*} params 
 * @param {*} success 
 * @param {*} fail 
 */
const foodRecommendListFunc = (params, success, fail) => {
  post(foodRecommendListUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}



/**
 * 菜系详情
 * @param {*} params 
 * @param {*} success 
 * @param {*} fail 
 */
const foodTypeDetailFunc = (params, success, fail) => {
  get(foodTypeDetailUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 获取openId
 */

const code2SessionFunc = (jsCode, success, fail) => {
  post(code2SessionUrl, {
    'jsCode': jsCode,
  }, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 用户登录，根据账号自动判断是商家还是用户
 */
const loginFunc = (params, success, fail) => {
  post(loginUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}


/**
 * 广告列表
 * @param {} params 
 * @param {*} success 
 * @param {*} fail 
 */
const bannerListFunc = (params, success, fail) => {
  get(bannerListUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}
/**
 * 添加笔记
 * @param {} params 
 * @param {*} success 
 * @param {*} fail 
 */
const addNotesFunc = (params, success, fail) => {
  get(addNotesUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 笔记列表
 * @param {*} params 
 * @param {*} success 
 * @param {*} fail 
 */
const listNotesFunc = (params, success, fail) => {
  get(listNotesUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}
/**
 * 删除笔记
 * @param {*} params 
 * @param {*} success 
 * @param {*} fail 
 */

const deleteNotesFunc = (params, success, fail) => {
  get(deleteNotesUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}
/**
 * 用户反馈
 * @param {} params 
 * @param {*} success 
 * @param {*} fail 
 */
const addFeedbackFunc = (params, success, fail) => {
  get(addFeedbackUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}

/**
 * 菜系列表
 * @param {} params 
 * @param {*} success 
 * @param {*} fail 
 */
const foodTypeListFunc = (params, success, fail) => {
  get(foodTypeListUrl, params, function (data) {
    success(data);
  }, function (res) {
    fail(res);
  })
}


/**
 * 把函数向外部暴露，方便直接调用
 */
export const serverUrl=serverHostUrl;
export const login = loginFunc;
export const banner_list = bannerListFunc;
export const add_notes = addNotesFunc;
export const list_notes = listNotesFunc;
export const delete_notes = deleteNotesFunc;
export const food_type_list = foodTypeListFunc;
export const food_type_detail = foodTypeDetailFunc;
export const food_recommend_list = foodRecommendListFunc;
export const food_detail = foodDetailFunc;
export const food_like = foodLikeFunc;
export const food_like_list = foodLikesFunc;
export const food_collect_list = foodCollectListFunc;
export const food_collect = foodCollectFunc;
export const food_comment = foodCommentFunc;
export const food_comment_list = foodCommentListFunc;
export const upload_file = uploadFileFunc;
export const publish_food = publishFoodFunc;
export const mine_foods = mineFoodsFunc;
export const category_detail = categoryDetailFunc;
export const user_feedback = addFeedbackFunc;
